#include <ctype.h>
#include <string.h>
#include <stdio.h>

#include "dualfifo.h"

char testString1[] = "Hello World.";
char testString2[] = "The quick brown fox jumped over the lazy";
char testString3[] = " squirrel";

void printBuffer( char * buffer, unsigned int size )
{
	unsigned int i;
	unsigned int haveNL = 0;
	
	for( i = 0; i < size; i++ )
	{
		if( isprint( buffer[i] ) )
		{
			fputc( buffer[i], stdout );
		}
		else
		{
			printf( "." );
		}
		
		if( i >0 && (i % 31) == 0 )
		{
			printf( "\n" );
			haveNL = 1;
		}
		else
		{
			haveNL = 0;
		}
	}
	
	if( !haveNL )
	{
		printf( "\n" );
	}
}


int main( void )
{
	dualfifo_t fifo;
	
	// Make a small fifo
	dualfifo_new( &fifo, 16, 128 );
	
	printBuffer( fifo.buffer, fifo.bufferSize );
	
	dualfifo_write( &fifo, testString1, strlen( testString1 ) );
	
	printBuffer( fifo.buffer, fifo.bufferSize );

	dualfifo_write( &fifo, testString2, strlen( testString2 ) );
	
	printBuffer( fifo.buffer, fifo.bufferSize );
	
	return 0;
}


